package com.portal.innovation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.portal.innovation.common.Constant;
import com.portal.innovation.utils.PageUtils;
import com.portal.innovation.dao.TeacherInfoDao;
import com.portal.innovation.pojo.TeacherInfo;
import com.portal.innovation.service.TeacherInfoService;
import org.springframework.stereotype.Service;

import java.util.HashMap;


@Service("teacherInfoService")
public class TeacherInfoServiceImpl extends ServiceImpl<TeacherInfoDao, TeacherInfo> implements TeacherInfoService {


    @Override
    public PageUtils queryPage(HashMap params) {
        Integer curPage = 1;
        Integer limit = 10;

        if (params.get(Constant.PAGE) != null) {
            curPage = Integer.parseInt(params.get(Constant.PAGE).toString());
        }
        if (params.get(Constant.LIMIT) != null) {
            limit = Integer.parseInt(params.get(Constant.LIMIT).toString());
        }
        //分页对象
        Page<TeacherInfo> page = new Page<>(curPage, limit);

        QueryWrapper<TeacherInfo> condition = new QueryWrapper<>();
        if(params.get("teacherName") != null){
            String key = params.get("teacherName").toString();
            if(StringUtils.isNotEmpty(key)){
                condition.like("teacher_name", key);
            }
        }

        PageUtils pageUtils = new PageUtils(this.page(page, condition));
        return pageUtils;
    }

}